home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Utilities / WBStars / source / WBStars_plot.c < prev    next >
C/C++ Source or Header  |  1996-07-23  |  5KB  |  254 lines

  1. /* $VER: WBStars_plot.c 1.04 (23.07.1996) */
  2.  
  3. #include "WBStars_include.h"
  4. #include "WBStars_protos.h"
  5. #include "WBStars_gui.h"
  6.  
  7. #define    SCX(x)        ((short)(((0.5*(x)/SCB)+0.5)*((double)maxx)))
  8. #define    SCY(y)        ((short)(((0.5*(y)/SCB)+0.5)*((double)maxy)))
  9. #define    leng(s)        (sqrt(star[(s)].x3*star[(s)].x3+star[(s)].y3*star[(s)].y3+star[(s)].z3*star[(s)].z3))
  10. #define rndneg()    (2.0*((double)(rand()-INT_MAX/2))/(double)INT_MAX)
  11.  
  12. double    COCH[10]={0.3, 1.0, 10.0, 39.0, 102.0, 214.0, 392.0, 656.0 ,1024.0 ,1516.0};
  13. double    SLEN;
  14. double    maxd;
  15. double    dx;
  16. double    dy;
  17. double    dz;
  18.  
  19. void    NewStars()
  20. {
  21.     char    i;
  22.  
  23.     SLEN=sqrt(sqrt((double)warpf));
  24.     maxd=2.0*c*(COCH[warpf]+1.0)/sqrt((double)warpf+1.0);
  25.     dx=-0.04*c*COCH[warpf]*sin(((double)az)*PI/180.0);
  26.     dy=-0.04*c*COCH[warpf]*sin(((double)he)*PI/180.0);
  27.     dz=-0.04*c*COCH[warpf]*cos(((double)az)*PI/180.0)*cos(((double)he)*PI/180.0);
  28.     for(i=0; i<anzstars; i++)
  29.     {
  30.         NewStar(i);
  31.     }
  32. }
  33.  
  34. void    NewStar( char i )
  35. {
  36.     double    azimut;
  37.     double    height;
  38.     double    temp;
  39.     char    flag=FALSE;
  40.  
  41.     do
  42.     {
  43.         azimut=rndneg()*PI;
  44.         height=rndneg()*PID2;
  45.         star[i].x3=maxd*sin(azimut);
  46.         star[i].y3=maxd*sin(height);
  47.         star[i].z3=maxd*cos(azimut)*cos(height);
  48.  
  49.         if(star[i].z3<dz*SLEN+1.0)
  50.         {
  51.             if(dz>0.0)
  52.             {
  53.                 temp=(dz*SLEN+1.0-star[i].z3)/dz;
  54.                 star[i].z3=dz*SLEN+1.0;
  55.                 star[i].x3=star[i].x3+dx*temp;
  56.                 star[i].y3=star[i].y3+dy*temp;
  57.                 if( leng(i)<maxd )
  58.                 {
  59.                     flag=TRUE;
  60.                 }
  61.             }
  62.         }
  63.         else
  64.         {
  65.             flag=TRUE;
  66.         }
  67.     }while(!flag);
  68.  
  69.     star[i].anzpoints=0;
  70. }
  71.  
  72. void    ClearStar( char i )
  73. {
  74.     char    n;
  75.     BYTE    drmd;
  76.  
  77.     if(star[i].anzpoints>0)
  78.     {
  79.         for( n=0; n<star[i].anzpoints; n++)
  80.         {
  81.             if( mode==MODE_WIN )
  82.             {
  83.                 SetAPen(RastP,bgpen);
  84.                 WritePixel(RastP,star[i].x[n],star[i].y[n]);
  85.             }
  86.             else
  87.             {
  88.                 if( ReadPixel(RastP,star[i].x[n],star[i].y[n])==star[i].col[n] )
  89.                 {
  90.                     Forbid();
  91.                     drmd=RastP->DrawMode;
  92.                     if((drmd==JAM1)||(drmd==JAM2))
  93.                     {
  94.                         SetAPen(RastP,bgpen);
  95.                         WritePixel(RastP,star[i].x[n],star[i].y[n]);
  96.                     }
  97.                     else
  98.                     {
  99.                         SetDrMd(RastP,JAM1);
  100.                         SetAPen(RastP,bgpen);
  101.                         WritePixel(RastP,star[i].x[n],star[i].y[n]);
  102.                         SetDrMd(RastP,drmd);
  103.                     }
  104.                     Permit();
  105.                 }
  106.             }
  107.         }
  108.         star[i].anzpoints=0;
  109.     }
  110. }
  111.  
  112. void    PlotStar( char i )
  113. {
  114.     double    fx,fy,fx2,fy2;
  115.     short    x,y,dx2,dy2,e,c1,c2;
  116.     short    ix1=1,iy1=0;
  117.     short    ix2=0,iy2=1;
  118.     short    brightn;
  119.     char    pix,n;
  120.     char    color;
  121.     BYTE    drmd;
  122.  
  123.     star[i].x3=star[i].x3+dx;
  124.     star[i].y3=star[i].y3+dy;
  125.     star[i].z3=star[i].z3+dz;
  126.     if( (leng(i)>=maxd) || (star[i].z3<1.0) || (star[i].z3<1.0+SLEN*dz) )
  127.     {
  128.         NewStar(i);
  129.     }
  130.     fx2=star[i].x3/star[i].z3;
  131.     fy2=star[i].y3/star[i].z3;
  132.     fx=(star[i].x3-dx*SLEN)/(star[i].z3-dz*SLEN);
  133.     fy=(star[i].y3-dy*SLEN)/(star[i].z3-dz*SLEN);
  134.     star[i].anzpoints=0;
  135.  
  136.     if( ((abs(fx2)<SCB)&&(abs(fy2)<SCB)) || ((abs(fx)<SCB)&&(abs(fy)<SCB)) )
  137.     {
  138.         if(warpf==0)
  139.         {
  140.             if(((abs(fx2)<SCB)&&(abs(fy2)<SCB))&&ReadPixel(RastP,SCX(fx2),SCY(fy2))==bgpen)
  141.             {
  142.                 color=coltable[abs(15-(short)((16.0*star[i].z3)/maxd))][6];
  143.                 star[i].anzpoints=1;
  144.                 star[i].x[0]=SCX(fx2);
  145.                 star[i].y[0]=SCY(fy2);
  146.  
  147.                 if(mode==MODE_WIN)
  148.                 {
  149.                     SetAPen(RastP,color);
  150.                     WritePixel(RastP,star[i].x[0],star[i].y[0]);
  151.                 }
  152.                 else
  153.                 {
  154.                     star[i].col[0]=color;
  155.                     Forbid();
  156.                     drmd=RastP->DrawMode;
  157.                     if((drmd==JAM1)||(drmd==JAM2))
  158.                     {
  159.                         SetAPen(RastP,color);
  160.                         WritePixel(RastP,star[i].x[0],star[i].y[0]);
  161.                     }
  162.                     else
  163.                     {
  164.                         SetDrMd(RastP,JAM1);
  165.                         SetAPen(RastP,color);
  166.                         WritePixel(RastP,star[i].x[0],star[i].y[0]);
  167.                         SetDrMd(RastP,drmd);
  168.                     }
  169.                     Permit();
  170.                 }
  171.             }
  172.         }
  173.         else
  174.         {
  175.             dx2=SCX(fx2)-SCX(fx);
  176.             dy2=SCY(fy2)-SCY(fy);
  177.             if(dx2<0)ix1=-1;
  178.             if(dy2<0)iy2=-1;
  179.             dx2=abs(dx2);
  180.             dy2=abs(dy2);
  181.             if(dx2<dy2)
  182.             {        
  183.                 pix=dy2+1;
  184.                 ix2=ix1;
  185.                 ix1=0;
  186.                 iy1=iy2;
  187.                 iy2=0;
  188.                 c1=2*dx2;
  189.                 e=c1-dy2;
  190.                 c2=e-dy2;
  191.             }
  192.             else
  193.             {
  194.                 pix=dx2+1;
  195.                 c1=2*dy2;
  196.                 e=c1-dx2;
  197.                 c2=e-dx2;
  198.             }
  199.             x=SCX(fx2);
  200.             y=SCY(fy2);
  201.             pix=min(pix,MAXPOINTS)-2;
  202.             brightn=abs(15-(short)((16.0*star[i].z3)/maxd));
  203.  
  204.             for(n=0; n<pix; n++)
  205.             {
  206.                 if((x>0)&&(x<maxx)&&(y>0)&&(y<maxy)&&(ReadPixel(RastP,x,y)==bgpen))
  207.                 {
  208.                     color=coltable[brightn][n*16/pix];
  209.                     star[i].x[star[i].anzpoints]=x;
  210.                     star[i].y[star[i].anzpoints]=y;
  211.                     star[i].anzpoints++;
  212.  
  213.                     if(mode==MODE_WIN)
  214.                     {
  215.                         SetAPen(RastP,color);
  216.                         WritePixel(RastP,x,y);
  217.                     }
  218.                     else
  219.                     {
  220.                         star[i].col[star[i].anzpoints-1]=color;
  221.                         Forbid();
  222.                         drmd=RastP->DrawMode;
  223.                         if((drmd==JAM1)||(drmd==JAM2))
  224.                         {
  225.                             SetAPen(RastP,color);
  226.                             WritePixel(RastP,x,y);
  227.                         }
  228.                         else
  229.                         {
  230.                             SetDrMd(RastP,JAM1);
  231.                             SetAPen(RastP,color);
  232.                             WritePixel(RastP,x,y);
  233.                             SetDrMd(RastP,drmd);
  234.                         }
  235.                         Permit();
  236.                     }
  237.                 }
  238.                 x=x+ix1;
  239.                 y=y+iy1;
  240.                 if(e<0)
  241.                 {
  242.                     e=e+c1;
  243.                 }
  244.                 else
  245.                 {
  246.                     e=e+c2;
  247.                     x=x+ix2;
  248.                     y=y+iy2;
  249.                 }
  250.             }
  251.         }
  252.     }
  253. }
  254.